home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK1.toast / Development Kits (Disc 1) / QuickDraw GX / Programming Stuff / GX Libraries / ColorMatchingLibrary.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-02  |  5.7 KB  |  128 lines  |  [TEXT/MPS ]

  1.  
  2. /*
  3.     File:        ColorMatchingLibrary.c
  4.  
  5.     Contains:    graphics libraries - gxColor matching library
  6.     
  7.                 The below code and data is an example, intended to illustrate graphics functionality.
  8.                 It is not part of the Graphics system provided as part of Macintosh System Software.
  9.                 Apple Computer, Inc. provides no liability, explicit or implied, for applications 
  10.                 using this example.  The Apple Developer Technical Support group is not able 
  11.                 to support this example.
  12.                 
  13.                 The numbers included in this library are not endorsements of the products described.
  14.                 The numbers have not been extensively tested to ensure their accuracy.     
  15.             
  16.     Written by:    Cary Clark, Georgiann Delaney, Michael Fairman, Dave Good, Robert Johnson, Keith McGreggor, Oliver Steele, David Van Brink, Chris Yerga
  17.  
  18.     Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  19.  
  20.     Change History (most recent first):
  21.  
  22.          <4>      5/2/95    jtd        bringing in final 1.1 source changes
  23.          <3>      4/7/95    jtd        revving to latest ColorSync headers
  24.          <2>     1/24/95    JD        updated to latest GX 1.1 source (as of 16 Jan 1995)
  25.          <1>      1/9/95    JD        First checked in.
  26. */
  27.  
  28.  
  29. #include <CMApplication.h>
  30. #include <Memory.h>
  31. #include "GraphicsLibraries.h"
  32.  
  33. /* data for the QMS Colorscript 100 / Four-color ribbon */
  34.  
  35. static CMXYZColor QMS_Chroma[8] = { 
  36.     {0x799d,    0x8000, 0x8b12},    /* white        0.3138, 0.3310, 100.00   */
  37.     {0x0000,    0x0000, 0x0000},    /* black        0.3138, 0.3310,  0.01    */
  38.     {0x2165,    0x102b, 0x028f},    /* red      0.5507, 0.3225, 18.57    */
  39.     {0x06cf,    0x13de, 0x08bb},    /* green        0.2342, 0.4732, 20.09    */
  40.     {0x0464,    0x02ee, 0x0fc5},    /* blue     0.1864, 0.1718,  5.68    */
  41.     {0x1618,    0x1da2, 0x54d7},    /* cyan     0.1728, 0.2523, 30.92    */
  42.     {0x25bc,    0x12c7, 0x1471},    /* magenta  0.4145, 0.2521, 22.58    */
  43.     {0x60bb,    0x6e87, 0x0d12}    /* yellow       0.4381, 0.4664, 84.14    */
  44. };
  45.  
  46. static gxColorValue QMS_Samples[] = {     11, 11, 11, 11, 11, 11, 11, 0, 0, 
  47.     0x0000, 0x19c7, 0x3c50, 0x5b22, 0x7c9e, 0xa3c2, 0xcb07, 0xe957, 0xf9e7, 0xfff8, 0xffff,
  48.     0x0000, 0x224d, 0x4587, 0x630b, 0x81a2, 0xa52b, 0xca22, 0xe885, 0xfa15, 0xff75, 0xffff,
  49.     0x0000, 0x21de, 0x4580, 0x65a7, 0x8709, 0xab42, 0xce34, 0xe964, 0xf943, 0xffa3, 0xffff,
  50.     0x0000, 0x2765, 0x4d63, 0x6bd9, 0x8ab2, 0xad21, 0xceb0, 0xe871, 0xf7e1, 0xffeb, 0xffff,
  51.     0x0000, 0x1e21, 0x3e3b, 0x5c1b, 0x7d63, 0xa2d0, 0xc6ba, 0xe287, 0xf466, 0xff89, 0xffff,
  52.     0x0000, 0x1f9d, 0x4247, 0x5e4f, 0x7d9e, 0xa44c, 0xcbbf, 0xe9a5, 0xf971, 0xfff1, 0xffff,
  53.     0x0000, 0x1ea4, 0x3b71, 0x56e9, 0x7703, 0x9d4f, 0xc4a7, 0xe46c, 0xf616, 0xfb0e, 0xffff };
  54.  
  55. gxColorProfile CreateQMSColorProfile(void)
  56. {
  57. /* note that just allocating a CMProfileRecord on the stack is asking for trouble, as it is a variable-sized structure. */
  58. /* When one puts the response curves into the record, previous stack frames get blown away, and things rapidly go */
  59. /* south from there (usually when we try to return from this function). Instead, temporarily allocating the space in */
  60. /* the heap keeps things intact. */
  61.     CMProfile *theProfile = (CMProfile*) NewPtr(sizeof(CMHeader)+sizeof(CMProfileChromaticities) + sizeof(CMIString) + 172);
  62.     long theSize;
  63.     CMIString *theString;
  64.     gxColorProfile theResult;
  65.     
  66.     if (!theProfile)
  67.         return nil;        /* not enough memory for the buffer. Just give back 'default' instead. */
  68.     
  69.     theProfile->header.CMMType = 'appl';
  70.     theProfile->header.applProfileVersion = cmCS1ProfileVersion;
  71.     theProfile->header.dataType = cmCMYKData;
  72.     theProfile->header.deviceType = cmPrinterDevice;
  73.     theProfile->header.deviceManufacturer = 0L;
  74.     theProfile->header.deviceModel = 0;
  75.     theProfile->header.deviceAttributes[0] = 0;
  76.     theProfile->header.deviceAttributes[1] = 0;
  77.     theProfile->header.flags = 0;
  78.     theProfile->header.options = cmPerceptualMatch;
  79.     
  80.     /* the following instruction is 'cheating' - I know that the colors are laid out as white, black, red, etc. */
  81.     /* in the ColorSync profile structure. */
  82.     BlockMove(QMS_Chroma, &theProfile->header.white, sizeof(CMXYZColor) * 8);
  83.     
  84.     BlockMove(QMS_Samples, &theProfile->response, 172);        /* This is 'cheating' as well. I know how large the response curves are */
  85.     
  86.     theSize = sizeof(CMHeader) + sizeof(CMProfileChromaticities) + 172;
  87.     theProfile->header.profileNameOffset = theSize;
  88.     
  89.     theString = (CMIString *) ((char *) theProfile + theSize);
  90.     theString->theScript = 0;
  91.     theString->theString[0] = 0;    /* no name at all - length 0 */
  92.  
  93.     theSize += sizeof(CMIString);
  94.     theProfile->header.size = theSize;
  95.     theProfile->header.customDataOffset = theSize;        /* there really isn't any custom data, however */
  96.     
  97.     theResult = GXNewColorProfile(theSize, (void *) theProfile);
  98.     DisposePtr((Ptr) theProfile);
  99.     return (theResult);
  100. }
  101.  
  102. /* data for the Canon BJ820 ... forthcoming... */
  103.  
  104. gxColorProfile CreateCanonColorProfile(void)
  105. {
  106.     return nil;     /* for now */
  107. }
  108.  
  109. /* returns a gxColorProfile with the current ColorSync system profile. ColorSync system profile is selected using the ColorSync */
  110. /* control panel. */
  111. /* Note that this routine assumes that ColorSync is installed. */
  112. /* Also note that this routine could easily be modified to create a CMProfileHandle -> gxColorProfile converter. */
  113. gxColorProfile CreateColorSyncSystemProfile(void)
  114. {
  115.     CMError theError;
  116.     CMProfileHandle theSystemProfile;
  117.     gxColorProfile result;
  118.  
  119.     theError = GetProfile(cmSystemDevice, 0, nil, &theSystemProfile);        /* Get the ColorSync system profile. */
  120.     if (theError || !theSystemProfile)
  121.         return nil;                /* in case something went wrong, just give back the default profile. */
  122.     HLock((Handle) theSystemProfile);        /* just in case we were put into the system heap and GX moves things in there. */
  123.     result = GXNewColorProfile((*theSystemProfile)->header.size, *theSystemProfile);
  124.     
  125.     DisposeHandle((Handle) theSystemProfile);
  126.     return result;
  127.  
  128. }